package com.deliveryservicesystem.app.validation;

import com.deliveryservicesystem.model.Delivery;
import com.jgoodies.binding.value.AbstractValueModel;
import com.jgoodies.common.base.Strings;
import com.jgoodies.validation.ValidationResult;
import com.jgoodies.validation.Validator;

/**
 * File Name: ProductValidator.java
 * Version:
 * Description:
 * Package: com.deliveryservicesystem.app.validation
 * Author: Lance
 * Date: Jun 29, 2012
 * Editor:
 */
public class RouteValidator extends AbstractValueModel implements Validator<ValidationResult>
{

    private static final long serialVersionUID = 1L;
    private String txtMainRoute;
    private Delivery cbDeliveryNo;

    public RouteValidator(String txtMainRoute, Object cbDeliveryNo)
    {
        this.txtMainRoute = txtMainRoute;
        this.cbDeliveryNo = (Delivery) cbDeliveryNo;
    }

    public Delivery getCbDeliveryNo()
    {
        return cbDeliveryNo;
    }

    public void setCbDeliveryNo(Delivery cbDeliveryNo)
    {
        this.cbDeliveryNo = cbDeliveryNo;
    }

    public String getTxtMainRoute()
    {
        return txtMainRoute;
    }

    public void setTxtMainRoute(String txtMainRoute)
    {
        this.txtMainRoute = txtMainRoute;
    }

    @Override
    public Object getValue()
    {
        return this;
    }

    @Override
    public void setValue(Object newValue)
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ValidationResult validate(ValidationResult validationTarget)
    {
        if (Strings.isEmpty(txtMainRoute.trim()))
        {
            validationTarget.addError("Main route required");
        }
        if (cbDeliveryNo == null)
        {
            validationTarget.addError("Please select a delivery number");
        }
        return validationTarget;
    }
}
